from aiohttpdemo_chat.main import main
if __name__ == '__main__':
    main()
# import asyncio
# import aiohttp
# from aiohttp import web
#
#
# class WebsocketEchoHandler:
#     @asyncio.coroutine
#     def __call__(self, request):
#         ws = web.WebSocketResponse()
#         ws.start(request)
#
#         connection = yield from asyncio_redis.Connection.create(host='127.0.0.1', port=6379)
#         subscriber = yield from connection.start_subscribe()
#         yield from subscriber.subscribe(['ch1', 'ch2'])
#
#         print('Connection opened')
#         try:
#             # Kick off both coroutines in parallel, and then block
#             # until both are completed.
#             yield from asyncio.gather(self.handle_ws(ws), self.handle_redis(subscriber))
#         except Exception as e:  # Don't do except: pass
#             import traceback
#             traceback.print_exc()
#         finally:
#             print('Connection closed')
#         return ws
#
#     @asyncio.coroutine
#     def handle_ws(self, ws):
#         while True:
#             msg_ws = yield from ws.receive()
#             if msg_ws:
#                 self.on_msg_from_ws(msg_ws)
#
#     @asyncio.coroutine
#     def handle_redis(self, subscriber):
#         while True:
#             msg_redis = yield from subscriber.next_published()
#             if msg_redis:
#                 self.on_msg_from_redis(msg_redis)
#
#
# if __name__ == "__main__":
#     app = aiohttp.web.Application()
#     app.router.add_route('GET', '/ws', WebsocketEchoHandler())
#
#     loop = asyncio.get_event_loop()
#     handler = app.make_handler()
#
#     f = loop.create_server(
#         handler,
#         '127.0.0.1',
#         8080,
#     )
#
#     srv = loop.run_until_complete(f)
#     print("Server started at {sock[0]}:{sock[1]}".format(
#         sock=srv.sockets[0].getsockname()
#     ))
#     try:
#         loop.run_forever()
#     except KeyboardInterrupt:
#         pass
#     finally:
#         loop.run_until_complete(handler.finish_connections(1.0))
#         srv.close()
#         loop.run_until_complete(srv.wait_closed())
#         loop.run_until_complete(app.finish())
#     loop.close()